package com.miracle9.game.dao;
import com.miracle9.game.entity.FishDesk;
import java.util.List;
import org.hibernate.Query;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Repository;

@Repository
public class FishDeskServiceDao extends SqlOperating<FishDesk, Integer>
{
  @Cacheable(value={"springCache"}, key="'getAllFishDesk'")
  public List<FishDesk> getFishDesks()
  {
    return q_CreateSqlList("from FishDesk order by roomId desc,orderBy", new Object[0]);
  }
  
  @Caching(evict={@org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'getAllFishDesk'"), @org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'getFishDesk'+#id")})
  public void updateOrderByById(int id, int index)
  {
	  q_CreateSql("update FishDesk set orderBy=? where id=?", new Object[] { Integer.valueOf(index), Integer.valueOf(id) }).executeUpdate();
  }
  
  @Cacheable(value={"springCache"}, key="'countFishDesk'+#roomId")
  public int getQuantityByRoomId(int roomId)
  {
    return q_CreateSqlInt("select count(*) from FishDesk where roomId = ?", new Object[] { Integer.valueOf(roomId) });
  }
  
  @Caching(evict={@org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'getAllFishDesk'"), @org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'countFishDesk'+#desk.roomId")})
  public Integer saveReturnInteger(FishDesk desk)
  {
      return (Integer) saveReturn(desk);
  }
  
  @Cacheable(value={"springCache"}, key="'getFishDesk'+#id")
  public FishDesk getFishDesk(int id)
  {
    return (FishDesk)getById(Integer.valueOf(id));
  }
  
  @Caching(evict={@org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'getAllFishDesk'"), @org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'getFishDesk'+#id")})
  public void updateSumById(int id)
  {
	  q_CreateSql("update FishDesk set sumYaFen=0,sumDeFen=0,sumSeat1YaFen=0,sumSeat2YaFen=0,sumSeat3YaFen=0,sumSeat4YaFen=0,sumSeat1DeFen=0,sumSeat2DeFen=0,sumSeat3DeFen=0,sumSeat4DeFen=0 where id=?", new Object[] { Integer.valueOf(id) }).executeUpdate();
  }
  
  @Caching(evict={@org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'getAllFishDesk'"), @org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'getFishDesk'+#desk.id")})
  public void updateFishDeskInfo(FishDesk desk)
  {
    FishDesk update = getFishDesk(desk.getId());
    update.setName(desk.getName());
    update.setMinGold(desk.getMinGold());
    update.setExchange(desk.getExchange());
    update.setOnceExchangeValue(desk.getOnceExchangeValue());
    update.setGameDiff(desk.getGameDiff());
    update.setSiteType(desk.getSiteType());
    update.setAutoKick(desk.getAutoKick());
    update.setMinGunValue(desk.getMinGunValue());
    update.setMaxGunValue(desk.getMaxGunValue());
    update.setAddstepGunValue(desk.getAddstepGunValue());
    update.setState(desk.getState());
    update.setDevice(desk.getDevice());
    update.setSeat(desk.getSeat());
    update(update);
  }
  
  @Caching(evict={@org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'getAllFishDesk'"), @org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'getFishDesk'+#id"), @org.springframework.cache.annotation.CacheEvict(value={"springCache"}, key="'countFishDesk'+#roomId")})
  public void deleteById(int id, int roomId)
  {
	  deleteById(Integer.valueOf(id));
  }
  
  public void updateStateById(int id, int state)
  {
	  q_CreateSql("update FishDesk set state=? where id=?", new Object[] { Integer.valueOf(state), Integer.valueOf(id) }).executeUpdate();
  }
}
